package demo;

public class Demo2 {
    public static void main(String[] args) {
        Object object = new Object();

        Thread t1 = new Thread(() -> {
            System.out.println("wait 之前");
            synchronized (object){
                try {
//                    object.wait();
                    object.wait(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("wait 之后");
        });

        Thread t2 = new Thread(() -> {
            try {
//                Thread.sleep(1000);
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (object){
                object.notify();
                System.out.println("唤醒 wait");
            }
        });

        t1.start();
        t2.start();
    }
}
